<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <meta name="viewport"
        content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0" />
    <meta name="format-detection" content="telephone=no,email=no,date=no,address=no">
    <link rel="stylesheet" type="text/css" href="../css/aui.2.0.css" />
    <link rel="stylesheet" type="text/css" href="../css/aui-flex.css" />
    <style>
    </style>
</head>
<style>
    .home:before {
        content: url(../image/home.png);
    }

    .refresh:before {
        content: url(../image/refresh.png);
    }

    .company:before {
        content: url(../image/company.png);
    }

    .pa-title {
        font-size: 17px;
        color: black;
        font-weight: bold;
    }

    .pa-title-content {
        font-size: 17px;
        color: black;
    }

    body {
        background-color: #D9D8DB;
    }

    .pa_scbg_left_top {
        background-color: #254060;
        border-radius: 5px;
        height: 80px;
        color: white;
    }

    .pa_scbg_left_bottom {
        background-color: #254060;
        height: 350px;
        border-radius: 5px;
        color: white;
        margin-top: 10px;
        overflow: auto;
    }

    .pa_scbg_right {
        background-color: #254060;
        height: 440px;
        border-radius: 5px;
        color: white;
        margin-left: 10px;
    }

    .pa_scbg_but {
        height: 50px;
        line-height: 50px;
        margin-top: 15px;
        margin-left: 12px;
        float: left;
        width: 111px;
        font-size: 18px;
        color: white;
        text-align: center;
    }

    .pa_scbg_content {
        font-size: 15px;
        color: white;
        margin-top: 5px;
    }

    p {
        font-size: 17px;
        color: black;
        font-weight: bold;
        text-align: center;
    }

    table {
        width: 100%;
        table-layout: fixed;
        word-wrap: break-word;
    }

    td {
        white-space: nowrap;
        text-overflow: ellipsis;
        overflow: hidden;
    }
</style>

<body>
    <header class="aui-bar aui-bar-nav" style="background-color: #D9D8DB">
        <div style="width: 10%;height: 60px;float: left;padding-top: 6px;">
            <a class="aui-pull-left aui-btn ">
                <span class="aui-iconfont company"></span>
            </a>
        </div>
        <div style="width: 10%;height: 60px;float: left;">
            <div style="text-align: left;">
                <span class="pa-title">富晟安创</span>
            </div>
        </div>
        <div style="width: 70%;height: 60px;float: left;">
            <div style="width:18%; float: left; text-align: left;">
                <span class="pa-title-content" id="locationName"></span>
            </div>
            <div style="width:18%; float: left; text-align: left;">
                <span class="pa-title-content" id="workCenterName"></span>
            </div>
            <div style="width:24%; float: left; text-align: left;">
                <span class="pa-title-content" id="workCellName"></span>
            </div>
            <div style="width:40%; float: left; text-align: left;">
                <span class="pa-title-content" id="nowDate"></span>
            </div>
        </div>
        <div style="width: 5%;height: 50px;float: left;">
            <a class="aui-pull-right aui-btn " onclick="refresh()">
                <span class="aui-iconfont refresh"></span>
            </a>
        </div>
        <div style="width: 5%;height: 50px;float: left;">
            <a class="aui-pull-right aui-btn" onclick="closeWin()">
                <span class="aui-iconfont home"></span>
            </a>
        </div>
    </header>
    <div class="aui-content">
        <div class="aui-flex-col aui-flex-center" style="height: 30px;">
            <div class="aui-flex-item-12">
                <p>报工</p>
            </div>
        </div>

        <div class="aui-flex-col aui-flex-center" style="margin-left: 1%;margin-right: 1%;">
            <div class="aui-flex-item-9">
                <div class="aui-flex-col pa_scbg_left_top">
                    <div class="pa_scbg_but" style="background-color: #00BFBF;" onclick="openReport()">合格品报工</div>
                    <div class="pa_scbg_but" style="background-color: #D9001B;" onclick="openUnReport()">不合格品报工</div>
                    <div class="pa_scbg_but" style="background-color: #00BFBF;" onclick="back()">撤销</div>
                    <div class="pa_scbg_but" style="background-color: #528302;" onclick="complete()">完工</div>
                    <div class="pa_scbg_but" style="background-color: #D9001B;" onclick="cancle()">关闭</div>
                </div>

                <div class="aui-flex-col pa_scbg_left_bottom">
                    <div class="aui-flex-item-12">
                        <div style="height: 100%;width: 100%;">
                            <table class="table" border="1px solid gray" cellspacing="0" cellpadding="0">
                                <thead>
                                    <tr style="text-align: center;color: white;font-size: 18px;height: 40px;">
                                        <td algin='center' style="width:4%;"></td>
                                        <td algin='center' style="width:7%">序号</td>
                                        <td algin='center' style="width:20%">容器码</td>
                                        <td algin='center' style="width:20%">批次</td>
                                        <td algin='center' style="width:11%">数量</td>
                                        <td algin='center' style="width:15%">报工类型</td>
                                        <td algin='center' style="width:23%">报工时间</td>
                                        <td style="display: none;">sysid</td>
                                    </tr>
                                </thead>
                                <tbody id="reportDataHtml">
                                </tbody>
                            </table>
                        </div>
                    </div>
                </div>
            </div>

            <div class="aui-flex-item-3">
                <div class="aui-flex-col pa_scbg_right">
                    <div class="aui-flex-item-12">
                        <div style="font-size:20px;color:white;font-weight:bold;margin-top: 10px;">
                            -----工厂基本信息-----
                        </div>
                        <div class="pa_scbg_content">
                            <span>工&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp厂:</span>
                            <span id="siteName">长春工厂</span>
                        </div>
                        <div class="pa_scbg_content">
                            <span>生产日期:</span>
                            <span id="prodDate"></span>
                        </div>
                        <div class="pa_scbg_content">
                            <span>生&nbsp&nbsp产&nbsp&nbsp线:</span>
                            <span id="lineName"></span>
                        </div>
                        <div class="pa_scbg_content">
                            <span>班&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp次:</span>
                            <span id="shiftName"></span>
                        </div>

                        <div style="font-size:20px;color:white;font-weight:bold;margin-top:50px;">
                            -----生产基本信息-----
                        </div>
                        <div class="pa_scbg_content">
                            <span>工&nbsp&nbsp单&nbsp&nbsp号:</span>
                            <span id="workOrderCode"></span>
                        </div>
                        <div class="pa_scbg_content">
                            <span>物料编码:</span>
                            <span id="mrlCode"></span>
                        </div>
                        <div class="pa_scbg_content">
                            <span>物料名称:</span>
                            <span id="mrlName"></span>
                        </div>
                        <div class="pa_scbg_content">
                            <span>计&nbsp&nbsp划&nbsp&nbsp数:</span>
                            <span id="planQty"></span>
                        </div>
                        <div class="pa_scbg_content">
                            <span>合&nbsp&nbsp格&nbsp&nbsp数:</span>
                            <span id="qualifyQty"></span>
                        </div>
                        <div class="pa_scbg_content">
                            <span>不合格数:</span>
                            <span id="unQualifyQty"></span>
                        </div>
                        <div class="pa_scbg_content">
                            <span>完&nbsp&nbsp工&nbsp&nbsp数:</span>
                            <span id="completeQty"></span>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</body>
<script type="text/javascript" src="../script/api.js"></script>
<script type="text/javascript" src="../script/jquery-1.8.2.min.js"></script>
<script type="text/javascript" src="../script/public.js"></script>
<script type="text/javascript">

    var equipUniqueId = "";

    //初始化
    apiready = function () {
        //获取设备唯一号
        equipUniqueId = localStorage.getItem('equipUniqueId');
        //产线工位信息
        document.getElementById("locationName").innerHTML = api.pageParam.locationName;
        document.getElementById("workCenterName").innerHTML = api.pageParam.workCenterName;
        document.getElementById("workCellName").innerHTML = api.pageParam.workCellName;
        document.getElementById("nowDate").innerHTML = getTimeCommon();
        //当前时间刷新
        window.setInterval("getTime()", 1000);

        document.getElementById("siteName").innerHTML = api.pageParam.siteName;
        document.getElementById("prodDate").innerHTML = api.pageParam.proddate;
        document.getElementById("lineName").innerHTML = api.pageParam.workCenterName;
        document.getElementById("shiftName").innerHTML = api.pageParam.shiftName;

        //工单号存在
        if (api.pageParam.workOrderCode != null && api.pageParam.workOrderCode != "" && api.pageParam.workOrderCode != undefined) {

            //查询工单信息
            doSearchWorkOrder();

            //查询报工数据
            doSearch();
        }
    }

    //时间刷新
    function getTime() {
        document.getElementById("nowDate").innerHTML = getTimeCommon();
    }

    //查询工单信息
    function doSearchWorkOrder() {
        var un = localStorage.getItem('un');
        var serverUrl = localStorage.getItem('serverUrl');
        var url = serverUrl + "/app/getAssemblyWorkOrder";
        var data = {
            values: {
                workOrderCode: api.pageParam.workOrderCode,
                proddate: api.pageParam.proddate,
                workCenterCode: api.pageParam.workCenterCode,
                workCenterName: api.pageParam.workCenterName,
                shiftCode: api.pageParam.shiftCode,
                state: "开工",
                un: un,
            }
        };
        var params = new Object();
        params.url = url;
        params.dataType = 'json';
        params.method = 'post';

        ajaxForData(params, data, false, function (ret, err) {
            if (ret) {
                var data = JSON.stringify(ret);
                var myobj = eval("(" + data + ")");
                if (myobj.code == 0) {

                    var list = eval(myobj.list);
                    if (list != null && list.length > 0) {
                        document.getElementById("workOrderCode").innerHTML = list[0].workOrderCode;
                        document.getElementById("mrlCode").innerHTML = list[0].mrlCode;
                        document.getElementById("mrlName").innerHTML = list[0].mrlName;
                        document.getElementById("planQty").innerHTML = list[0].planQty;
                        document.getElementById("qualifyQty").innerHTML = list[0].qualifyQty;
                        document.getElementById("unQualifyQty").innerHTML = list[0].unQualifyQty;
                        document.getElementById("completeQty").innerHTML = list[0].completeQty;
                    } else {
                        document.getElementById("workOrderCode").innerHTML = '';
                        document.getElementById("mrlCode").innerHTML = '';
                        document.getElementById("mrlName").innerHTML = '';
                        document.getElementById("planQty").innerHTML = '';
                        document.getElementById("qualifyQty").innerHTML = '';
                        document.getElementById("unQualifyQty").innerHTML = '';
                        document.getElementById("completeQty").innerHTML = '';
                    }
                } else {
                    api.toast({
                        msg: myobj.message,
                        duration: 3000
                    });
                }
            } else {
                alert("网络连接超时!")
            }
        });
    }

    //查询报工信息
    function doSearch() {
        var un = localStorage.getItem('un');
        var serverUrl = localStorage.getItem('serverUrl');
        var url = serverUrl + "/app/getAssemblyReport";
        var data = {
            values: {
                workOrderCode: api.pageParam.workOrderCode,
                un: un,
            }
        };
        var params = new Object();
        params.url = url;
        params.dataType = 'json';
        params.method = 'post';

        ajaxForData(params, data, false, function (ret, err) {
            if (ret) {
                var data = JSON.stringify(ret);
                var myobj = eval("(" + data + ")");

                //成功
                if (myobj.code == 0) {
                    var list = eval(myobj.list);
                    var html = "";
                    //遍历
                    for (var i = 0; i < list.length; i++) {
                        html += "<tr style='text-align: center;color: white;font-size: 14px;height:50px;'>";
                        html += "<td><input name='sub' type='checkbox' /></td>"
                        html += "<td name='index'>" + (i + 1) + "</td>";
                        html += "<td name='containerTm'>" + list[i].containerTm + "</td>";
                        html += "<td name='lotCode'>" + list[i].lotCode + "</td>";
                        html += "<td name='qty'>" + list[i].qty + "</td>";
                        html += "<td name='type'>" + list[i].type + "</td>";
                        html += "<td name='endTimestamp'>" + list[i].endTimestamp + "</td>";
                        html += "<td name='sysid' style='display:none;'>" + list[i].sysid + "</td>";
                        html += "</tr>";
                    }

                    $api.html($api.byId("reportDataHtml"), html);
                } else {
                    $api.html($api.byId("reportDataHtml"), "");
                    api.toast({
                        msg: myobj.message,
                        duration: 3000
                    });
                }
            } else {
                alert("网络连接超时!")
            }
        });
    }

    function chkValid() {
        var workOrderCode = document.getElementById("workOrderCode").innerHTML;
        if (workOrderCode == null || workOrderCode == "" || workOrderCode == undefined) {
            api.toast({
                msg: "工单号为空，不允许报工!",
                duration: 3000
            });
            return false;
        } else {
            return true;
        }
    }

    //合格品报工
    function openReport() {
        var flag = chkValid();
        if (flag) {
            var pageParam = api.pageParam;
            pageParam.workOrderCode = document.getElementById("workOrderCode").innerHTML;
            if (api.pageParam.rootName == "productionAssemblyElectroplate") {
                api.openWin({
                    name: "productionAssemblyScbgDd_OK",
                    url: 'productionAssemblyScbgDd_OK.html',
                    pageParam: pageParam,
                });
            } else {
                api.openWin({
                    name: "productionAssemblyScbg_OK",
                    url: 'productionAssemblyScbg_OK.html',
                    pageParam: pageParam,
                });
            }
        }
    }

    //不合格品报工
    function openUnReport() {
        var flag = chkValid();
        if (flag) {
            var pageParam = api.pageParam;
            pageParam.workOrderCode = document.getElementById("workOrderCode").innerHTML;
            if (api.pageParam.rootName == "productionAssemblyElectroplate") {
                api.openWin({
                    name: "productionAssemblyScbgDd_NG",
                    url: 'productionAssemblyScbgDd_NG.html',
                    pageParam: pageParam,
                });
            } else {
                api.openWin({
                    name: "productionAssemblyScbg_NG",
                    url: 'productionAssemblyScbg_NG.html',
                    pageParam: pageParam,
                });
            }
        }
    }

    //撤销
    function back() {
        //选中数据
        var check = $("input[type='checkbox']:checked"); //在table中找input下类型为checkbox属性为选中状态的数据
        var count = 0;
        var sysid = "";
        check.each(function () { //遍历
            var row = $(this).parent("td").parent("tr");
            sysid = row.find("[name='sysid']").html();
            count++;
        });

        if (count != 1) {
            api.toast({
                msg: "请选择一条表格数据",
                duration: 3000
            });
            return;
        }

        var un = localStorage.getItem('un');
        var serverUrl = localStorage.getItem('serverUrl');
        var url = serverUrl + "/app/getAssemblyReportReturnSave";
        var data = {
            values: {
                sysid: sysid,
                un: un,
            }
        };
        var params = new Object();
        params.url = url;
        params.dataType = 'json';
        params.method = 'post';

        api.showProgress({
            title: '保存中...',
        });
        ajaxForData(params, data, false, function (ret, err) {
            if (ret) {
                api.hideProgress();
                var data = JSON.stringify(ret);
                var myobj = eval("(" + data + ")");

                //成功
                if (myobj.code == 0) {
                    api.toast({
                        msg: "撤销成功",
                        duration: 3000
                    });

                    //刷新数据
                    refresh();

                } else {
                    api.toast({
                        msg: myobj.message,
                        duration: 3000
                    });
                }
            } else {
                api.hideProgress();
                alert("网络连接超时!")
            }
        });
    }

    //完工
    function complete() {
        var flag = chkValid();
        if (flag) {
            var un = localStorage.getItem('un');
            var serverUrl = localStorage.getItem('serverUrl');
            var url = serverUrl + "/app/getAssemblyUpdateWorkOrder";
            var data = {
                values: {
                    workOrderCodeStr: api.pageParam.workOrderCode,
                    workCenterCode: api.pageParam.workCenterCode,
                    workCellCode: api.pageParam.workCellCode,
                    state: "完工",
                    un: un,
                }
            };
            var params = new Object();
            params.url = url;
            params.dataType = 'json';
            params.method = 'post';

            ajaxForData(params, data, false, function (ret, err) {
                if (ret) {
                    var data = JSON.stringify(ret);
                    var myobj = eval("(" + data + ")");

                    //成功
                    if (myobj.code == 0) {
                        api.toast({
                            msg: "保存成功",
                            duration: 3000
                        });

                        cancle();

                    } else {
                        api.toast({
                            msg: myobj.message,
                            duration: 3000
                        });
                    }
                } else {
                    alert("网络连接超时!")
                }
            });
        }
    }

    //刷新按钮
    function refresh() {
        //获取设备唯一号
        equipUniqueId = localStorage.getItem('equipUniqueId');

        var workOrderCode = document.getElementById("workOrderCode").innerHTML;
        if (workOrderCode != null && workOrderCode != "" && workOrderCode != undefined) {
            //查询工单信息
            doSearchWorkOrder();

            //查询报工数据
            doSearch();
        }
    }

    //返回上级页面
    function cancle() {
        api.closeWin({});
        api.execScript({
            name: api.pageParam.name,
            script: 'refresh()'
        });
    }

    //返回按钮
    function closeWin() {
        api.closeToWin({ name: api.pageParam.rootName });
        api.execScript({
            name: api.pageParam.rootName,
            script: 'refresh()'
        });
    }
</script>

</html>